EventBus   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 4

4 Functions

Rating   Name   Duplication   Size   Complexity  
A off 0 3 1
A once 0 3 1
A on 0 3 1
A emit 0 3 1
1
import EventEmitter2 from 'eventemitter2';
2
3
export default class EventBus {
4
    public emitter: EventEmitter2;
5
6
    constructor() {
7
        this.emitter = new EventEmitter2();
8
    }
9
10
    public on(event: string, listener: (...args: any[]) => void) {
11
        return this.emitter.on(event, listener);
12
    }
13
14
    public off(event: string, listener: (...args: any[]) => void) {
15
        return this.emitter.off(event, listener);
16
    }
17
18
    public emit(event: string, ...args: any[]) {
19
        return this.emitter.emit(event, ...args);
20
    }
21
22
    public once(event: string, listener: (...args: any[]) => void) {
23
        return this.emitter.once(event, listener);
24
    }
25
}
26
27
export const eventbus = new EventBus();
28